import type { Column } from "@/components/CrudPage/type";

import {
  deleteAssetsDir,
  type AssetsDir
} from "@/views/domain/assets/api/assetsDir";
import { messager } from "@/utils/message";

export function useAssetsDirProvider() {
  // 列配置
  const columns: Column[] = [
    {
      label: "文件夹id",
      prop: "id",
      slot: "id",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件夹名称",
      prop: "name",
      slot: "name",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件夹路径",
      prop: "path",
      slot: "path",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "父文件夹id",
      prop: "pid",
      slot: "pid",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "操作",
      prop: "operation",
      slot: "operation"
    }
  ];

  // 删除row
  const deleteRow = (row: AssetsDir) => {
    deleteAssetsDir(row).then(({ ok, msg }) => {
      messager.alert(ok, msg);
    });
  };

  return {
    columns,
    deleteRow
  };
}
